//
//  TYMusicsViewController.m
//  黑马音乐盒
//
//  Created by 翟天宇 on 15/11/27.
//  Copyright © 2015年 翟天宇. All rights reserved.
//

#import "TYMusicsViewController.h"
#import "MJExtension.h"
#import "TYMusic.h"
#import "UIImage+Circle.h"
#import "TYPlayingViewController.h"

@interface TYMusicsViewController ()

//所有音乐的数组
@property (nonatomic, strong) NSArray *musics;

//正在播放的控制器
@property (nonatomic,strong) TYPlayingViewController *playingVc;

@end

@implementation TYMusicsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //改变cell的高度
    self.tableView.rowHeight = 80;
    
}
#pragma mark - 懒加载 
-(NSArray *)musics {
    if (_musics == nil) {
        self.musics = [TYMusic objectArrayWithFilename:@"Musics.plist"];
    }
    return _musics;
}
-(TYPlayingViewController *)playingVc {
    if (_playingVc == nil) {
        
        _playingVc = [[TYPlayingViewController alloc]init];
    }
    return _playingVc;
}

#pragma mark - Table view data source
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //1.让cell变为不选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    //2.弹出控制器
    [self.playingVc show];
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.musics.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ID = @"MusicCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    //1.取出模型对象
    TYMusic *music = self.musics[indexPath.row];
    
    //2.给cell设置数据
    cell.imageView.image = [UIImage circleImageWithName:music.singerIcon borderWidth:3.0 borderColor:[UIColor purpleColor]];
    cell.textLabel.text = music.name;
    cell.detailTextLabel.text = music.singer;
    
    return cell;

}


@end





















